Exercise: Heaps
Implement the remove(i) method in the binary heap.
We'll cover the following
Task#
Implement the remove(i) method, that removes the value stored in a[i] in a BinaryHeap. This method should run in time.
Sample input
The sample input will be as follows:
[0, 1, 2, 3, 4, 5, 6]
Expected output
The expected output will be as follows:
Original Heap:
[0, 1, 2, 3, 4, 5, 6]
Heap after removal from index 2:
[0, 1, 5, 3, 4, 6]
Try it yourself first. If you have trouble getting to the solution, you can move to the solution section to see how to solve the problem. We’ll go through the in-depth solution in the next lesson.
Good luck!
Note: You must implement the method
remove(i)in the below code starting at line 91.
main.py
base.py
utils.py
Task to implement remove() in BinaryHeap
Discussion on Heaps
Solution: Heaps